<?php
class IXUserIdentity extends CUserIdentity
{
    /**
     * 管理员验证
     */
    public function Oauth_authenticate()
    {
        $row = Users::model()->find('login_name=:name',array(':name'=>$this->username));
        $this->do_login_success($row);
        return $row->id;
    }

    public function Pwd_authenticate()
    {
        $row = Users::model()->find('login_name=:name',array(':name'=>$this->username));
        if($row->passwprd != IXCommon::hash_pwd($this->passwprd))
        {
            //TODO failed log
            //TODO check if banned
            return false;
        }
        $this->do_login_success($row);
        return $row->id;
    }

    private function do_login_success($user)
    {
        $user->lastlogin_time = date('Y-m-d H:i:s');
        $user->save();
        $this->setState('user_is_login', TRUE);
        $this->setState('uid', $user->id);
    }
}